package com.qf.web.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * A extends Annotation,  表示关联的校验注解
 * T 校验的数据类型
 */
public class TypeValidated implements ConstraintValidator<TypeValidator, String> {
    private String[] values;

    @Override
    public void initialize(TypeValidator constraintAnnotation) {
        //使用注解时固定的值
        this.values = constraintAnnotation.value().split(",");
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {

        return Arrays.asList(values).contains(s);
    }
}
